/*     */ package com.zimbra.cs.account.callback;
/*     */ 
/*     */ import com.zimbra.common.account.Key.ServerBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.AttributeCallback;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MailHost
/*     */   extends AttributeCallback
/*     */ {
/*     */   public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry)
/*     */     throws ServiceException
/*     */   {
/*  41 */     if ((StringUtil.isNullOrEmpty((String)value)) || (attrsToModify.get("-zimbraMailHost") != null))
/*     */     {
/*  43 */       return;
/*     */     }
/*  45 */     String mailHost = (String)value;
/*  46 */     String mailTransport = (String)attrsToModify.get("zimbraMailTransport");
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  51 */     if ((!StringUtil.isNullOrEmpty(mailHost)) && (!StringUtil.isNullOrEmpty(mailTransport))) {
/*  52 */       throw ServiceException.INVALID_REQUEST("setting both zimbraMailHost and zimbraMailTransport in the same request is not allowed", null);
/*     */     }
/*     */     
/*     */ 
/*  56 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  58 */     Server server = prov.get(Key.ServerBy.serviceHostname, mailHost);
/*  59 */     if (server == null) {
/*  60 */       throw ServiceException.INVALID_REQUEST("specified zimbraMailHost does not correspond to a valid server service hostname: " + mailHost, null);
/*     */     }
/*     */     
/*     */ 
/*  64 */     if (!server.hasMailClientService()) {
/*  65 */       throw ServiceException.INVALID_REQUEST("specified zimbraMailHost does not correspond to a mailclient server with service webapp enabled: " + mailHost, null);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  78 */     if ((entry != null) && (!context.isCreate()))
/*     */     {
/*  80 */       String oldMailHost = entry.getAttr("zimbraMailHost");
/*  81 */       if (oldMailHost != null) {
/*  82 */         Server oldServer = prov.get(Key.ServerBy.serviceHostname, oldMailHost);
/*  83 */         if (oldServer != null) {
/*  84 */           String curMailTransport = entry.getAttr("zimbraMailTransport");
/*  85 */           if (!oldServer.mailTransportMatches(curMailTransport)) {
/*  86 */             throw ServiceException.INVALID_REQUEST("current value of zimbraMailHost does not match zimbraMailTransport, computed mail transport from current zimbraMailHost=" + mailTransport(oldServer) + ", current zimbraMailTransport=" + curMailTransport, null);
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 100 */     String newMailTransport = mailTransport(server);
/* 101 */     attrsToModify.put("zimbraMailTransport", newMailTransport);
/*     */   }
/*     */   
/*     */   private static String mailTransport(Server server)
/*     */   {
/* 106 */     String serviceName = server.getAttr("zimbraServiceHostname", null);
/* 107 */     int lmtpPort = server.getIntAttr("zimbraLmtpBindPort", 7025);
/* 108 */     String transport = "lmtp:" + serviceName + ":" + lmtpPort;
/* 109 */     return transport;
/*     */   }
/*     */   
/*     */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/MailHost.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */